package org.next.tesigiulia.utils;

import com.gargoylesoftware.htmlunit.WebClient;
import gov.nasa.worldwind.BasicModel;
import gov.nasa.worldwind.awt.WorldWindowGLCanvas;
import gov.nasa.worldwind.layers.AnnotationLayer;
import gov.nasa.worldwind.layers.RenderableLayer;
import org.next.tesigiulia.controllers.AreaController;
import org.next.tesigiulia.controllers.TwitterWWJController;
import org.next.tesigiulia.models.Area;
import org.next.tesigiulia.models.AreasModel;
import org.next.tesigiulia.models.TwitterWWJModel;
import org.next.tesigiulia.views.AreaView;
import org.next.tesigiulia.views.TwitterWWJView;
import twitter4j.Twitter;
import twitter4j.TwitterFactory;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * Created with IntelliJ IDEA.
 * User: gianluca
 * Date: 07/01/13
 * Time: 16.11
 * To change this template use File | Settings | File Templates.
 */
public class Main {
    public static void main(String[] args) {
        createWWJ();
        createAreas();
        createTwitterHandler();
        createMarineScraper();

        // TwitterAreaHandler gestoreTwitterArea =new TwitterAreaHandler(twitter);
    }

    private static void createMarineScraper() {
        MarineScraper marineScraper = new MarineScraper(new WebClient(), 1000);
        try {
            marineScraper.start();
        } catch (IOException e) {
            Logger.getAnonymousLogger().log(Level.SEVERE, e.toString());
        }
    }

    private static void createTwitterHandler() {
        TwitterAreaBuilder twitterAreaBuilder = new TwitterAreaBuilder();
        Twitter twitter = TwitterFactory.getSingleton();

        TwitterAreaHandler twitterAreaHandler = new TwitterAreaHandler(twitterAreaBuilder, twitter);
    }


    private static void createAreas() {
        AreasModel model = new AreasModel();
        AreaView view = new AreaView();
        Area currentArea = new Area();
        AreaController areaController = new AreaController(model, view, currentArea);
        view.setController(areaController);
    }

    private static void createWWJ() {
        TwitterWWJModel model = new TwitterWWJModel();
        WorldWindowGLCanvas glCanvas = new WorldWindowGLCanvas();
        BasicModel bModel = new BasicModel();
        glCanvas.setModel(bModel);


        TwitterWWJView view = new TwitterWWJView(glCanvas);

        RenderableLayer renderableLayer = new RenderableLayer();
        view.setRenderableLayer(renderableLayer);

        AnnotationLayer annotationLayer = new AnnotationLayer();
        view.setAnnotantionLayer(annotationLayer);

        RenderableLayer vesselsLayer = new RenderableLayer();
        view.setVesselsLayer(vesselsLayer);

        TwitterWWJController twitterWWJController = new TwitterWWJController(model, view);
        view.setController(twitterWWJController);
    }
}
